package com.kabigon.producer;

import com.kabigon.message.Demo01Message;
import org.springframework.amqp.rabbit.AsyncRabbitTemplate;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author xu.biao
 * @version v1.0
 * @Package com.kabigon
 * @data 2023/3/5 16:30
 */
@Component
public class Demo01Producer {

    @Resource
    private AsyncRabbitTemplate asyncRabbitTemplate;

    @Resource
    private RabbitTemplate rabbitTemplate;


    public void syncSend(Integer id) {
        // 创建 Demo01Message 消息
        Demo01Message message = new Demo01Message();
        message.setId(id);
        // 同步发送消息
        rabbitTemplate.convertAndSend(Demo01Message.QUEUE, Demo01Message.ROUTING_KEY, message);
    }

    public void syncSendDefault(Integer id) {
        // 创建 Demo01Message 消息
        Demo01Message message = new Demo01Message();
        message.setId(id);
        // 同步发送消息
        rabbitTemplate.convertAndSend(Demo01Message.ROUTING_KEY, message);
    }


    public AsyncRabbitTemplate.RabbitConverterFuture<Void> asyncSend(Integer id) {
        Demo01Message message = new Demo01Message();
        message.setId(id);
        AsyncRabbitTemplate.RabbitConverterFuture<Void> future = asyncRabbitTemplate.convertSendAndReceive(Demo01Message.QUEUE, Demo01Message.ROUTING_KEY, message);
        return future;
    }

}
